package com.dnjn.happiness.survey.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.survey.domain.SurveyIntervalScore;
import com.dnjn.happiness.survey.domain.vo.SurveyIntervalScoreVO;
import com.dnjn.happiness.survey.service.ISurveyIntervalScoreService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 区间信息Controller
 *
 * @author happiness
 * @date 2023-11-16
 */
@Tag(name = "survey surveyIntervalScore 区间信息", description = "区间信息")
@RestController
@RequestMapping("/surveyIntervalScore")
public class SurveyIntervalScoreController extends BaseController {
    @Autowired
    private ISurveyIntervalScoreService surveyIntervalScoreService;

    /**
     * 查询区间信息列表
     */
    @RequiresPermissions("survey:surveyIntervalScore:list")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SurveyIntervalScoreVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        SurveyIntervalScore surveyIntervalScore = new SurveyIntervalScore();
        BeanUtils.copyPropsIgnoreNull(vo, surveyIntervalScore);
        Page page = Page.of(current, size);
        Page<SurveyIntervalScore> list = surveyIntervalScoreService.page(page, Wrappers.query(surveyIntervalScore));
        return success(list);
    }

    /**
     * 导出区间信息列表
     */
    //@Log(title = "区间信息", businessType = BusinessType.EXPORT)
    @RequiresPermissions("survey:surveyIntervalScore:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurveyIntervalScoreVO vo) {
        SurveyIntervalScore surveyIntervalScore = new SurveyIntervalScore();
        BeanUtils.copyPropsIgnoreNull(vo, surveyIntervalScore);

        List<SurveyIntervalScore> list = surveyIntervalScoreService.list(Wrappers.query(surveyIntervalScore));
        ExcelUtil<SurveyIntervalScore> util = new ExcelUtil<SurveyIntervalScore>(SurveyIntervalScore.class);
        util.exportExcel(response, list, "区间信息数据");
    }

    /**
     * 获取区间信息详细信息
     */
    @RequiresPermissions("survey:surveyIntervalScore:query")
    @GetMapping(value = "/{surveyIntervalScoreId}")
    public AjaxResult get(@PathVariable("surveyIntervalScoreId") Long surveyIntervalScoreId) {
        return success(surveyIntervalScoreService.getById(surveyIntervalScoreId));
    }

    /**
     * 新增区间信息
     */
    //@Log(title = "区间信息", businessType = BusinessType.INSERT)
    @RequiresPermissions("survey:surveyIntervalScore:add")
    @PostMapping
    public AjaxResult add(@RequestBody SurveyIntervalScoreVO vo) {
        SurveyIntervalScore surveyIntervalScore = new SurveyIntervalScore();
        BeanUtils.copyPropsIgnoreNull(vo, surveyIntervalScore);

        surveyIntervalScore.setCreateBy(SecurityUtils.getUsername());
        return toAjax(surveyIntervalScoreService.save(surveyIntervalScore));
    }

    /**
     * 修改区间信息
     */
    //@Log(title = "区间信息", businessType = BusinessType.UPDATE)
    @RequiresPermissions("survey:surveyIntervalScore:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyIntervalScoreVO vo) {
        SurveyIntervalScore surveyIntervalScore = new SurveyIntervalScore();
        BeanUtils.copyPropsIgnoreNull(vo, surveyIntervalScore);
        return toAjax(surveyIntervalScoreService.updateById(surveyIntervalScore));
    }

    /**
     * 删除区间信息
     */
    //@Log(title = "区间信息", businessType = BusinessType.DELETE)
    @RequiresPermissions("survey:surveyIntervalScore:remove")
    @DeleteMapping("/{surveyIntervalScoreIds}")
    public AjaxResult remove(@PathVariable Long[] surveyIntervalScoreIds) {
        return toAjax(surveyIntervalScoreService.removeBatchByIds(Arrays.asList(surveyIntervalScoreIds)));
    }
}
